/*  
     PlAr is Platform Arena: a 2D multiplayer shooting game
     Copyright (C) 2009 Ragagnin Antonio <spocchio@gmail.com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package plar.core.defaultElements;

import java.awt.Point;
import java.util.ArrayList;

import plar.core.Action;
import plar.core.Common;
import plar.core.Element;
import plar.core.Parameters;
import plar.core.Sprite;
import plar.core.defaultActions.Move;

public class Shoot extends Element {
	class CollisionPlayer implements Action {
		public CollisionPlayer() {

		}

		public Parameters call(Parameters parameters)

		{

			Element me = (Element) parameters.get("me");
			String subAction = (String) parameters.get("subAction");
			ArrayList<Element> collisions = (ArrayList<Element>) getProperty("collisionList");
			if (subAction == "main") {
				if (collisions != null)
					for (Element e : collisions) {
						if (e.getProperty("type") == "player") {
							Integer energy = (Integer) e.getProperty("energy");
							e.setProperty("energy", energy - 10);
							Common.info("shooted to:" + e);
						}
					}
				if (collisions != null)
					if (collisions.size() > 0) {
						parameters.put("subAction", "new");
						parameters.put("me", me);
						parameters.put("level", level);
						me.actions.runAction("destroy", parameters);
					}
			}
			return null;
		}
	}

	public Shoot() {
		super();

		setProperty("type", "shoot");
		setProperty("isRunnable", true);
		setProperty("runSpeed", 0);
		setProperty("runTimes", 1);

		Sprite s = new Sprite("res/fire.png", -1);
		ArrayList<Sprite> ss = new ArrayList<Sprite>();
		ss.add(s);
		setProperty("currentSpriteSet", ss);
		setProperty("canCollide", true);
		actions.addAction("collision", new CollisionPlayer());
		setProperty("direction", 0); // 0 = right, 1 =left its direction*pigreek
										// angle
		setSize(new Point(20, 20));
		actions.addAction("move", new Move());

	}

	@Override
	public void run() {

		super.run();

	}
}
